Script for setting the pose of an armsture to fit over another armature

Hello,
I am struggling to find a way to set the position of the pose of an armature to exactly fit over a second rig. I managed a script that sets the scale of the bones to represent the length of the bones of the second rig, but as the two rigs have their bone heads and tails at slightly offsetp positions still I will probably need to set the posebone rotation accordingly, and that is where I am struggling.

I will try to explain the background situation a bit more to make it more clear, I hope. I want to animate geadualy aging characters for a computer game. For proof of concept purposes I have imported to .mhx2 files from MakeHuman: a male infant and an adult.
I have scripted a morph target that changes the mesh from the baby chatacter to the adult version. But as the proportions are not exactly the same and as the corresponding t-poses are slightly off, the rig of the one chatacter is slightly off on the other one, like the bones of the fingers sticking out of the hand. This leads to weird behavior when animating. So I hope to find a way to script the pose of armature A to fit over the rest pose of armature B

I hope someone can help me here, or, if my attempt is totally off limits, point me in the right direction.
Regards and thanks in advanve
Stoon.