when the axis of your two objects is identical, you won't get anywhere with
BaseObject.GetMg() because that is that axis. The matrix/transform of an object in global space is (mg stands for matrix global) is just the coordinate system in which the points and child objects of an object operate.
Or in other words, when you have to go into point mode, select all points, and move, rotate, and scale them to match object Q onto object P, then you have to also manipulate the points in code.
Get/SetMg/Ml are the equivalent of moving, rotating, and scaling an object in object mode. The global matrix of an object IS quite literally its axis you see in the editor. So, when you have selected all points of object Q and randomly transformed them, you must find that transform. For that you need to establish a frame of reference for each object so that you can compute that transform delta between them. FInding these frames can be insanely hard when the objects do not share a topology; but they seem to do in your case.
When that is the case, an easy way to compute a frame (a.k.a., the orientation part of a transform, sometimes also called basis) is to construct one on a polygon with the same index of each object. In the Matrix Manual I showed once how to construct a transform from a vector and an up-vector. Here you would not even need an up-vector since a polygon defines all three degrees of freedom. For a triangle with the points a, b, and c and the edges e1, e2, and e3, you can construct a frame on point a with the edges e3 and e1 (see example in the manual for details). When you also want to compute the offset and not only orientation delta, you would have to define the point a as the offset of that constructed transform.
The delta of two transforms is computed with multiplication and the inversion operator. The inverse of a transform is its opposite operation. When you have a transform T which rotates by 90° on the x-axis and translate by -10 units on the y axis, then its inverse ~T would rotate by -90° on x and translate by 10 on y. Or in other words
T * ~T = 0. When we now have two non-identical transforms, we can compute in this manner their delta. For the transforms S and T,
M = S * ~T would for example be the transform that transforms from S to T; i.e.,
S * M = T.
When you have your delta, you just have to apply it to each point in the object you want to transform in this manner. :warning: I would recommend having a look at the geometry code examples I linked to above and the Matrix manual, as I went there already over a good deal of the basics. When you are then still stuck please share your existing code and we will help you .
 With the exception of higher level topics such as similarity metrics, i.e., the case that two objects look similar, but do not share a topology.