Apply mesh to BVH armature

I have a human mesh and a bvh file.
I import the bvh file as an armature.
I assign all vertices of the mesh to vertex groups that have the same names as the armature bones.
I then apply an armature modifier to the mesh.
I turn off “Envelopes”

Then the limbs of my mesh all skew all over the place giving me a crazy looking mess.
The mesh appears to be following the animation, but some of the limbs are miles away from the corresponding armature limb.

I have watched several armature tutorials, but I can’t work out what is going wrong.
I thought that maybe it was because my bvh has a funny rest position (arms and legs both going straight up), but I tried a different bvh from the web and got the same results.

Can anybody please give me some advice?

Also, if anbody is interested in a copy I have written an application to convert HTR files to BVH files.