How to move two masters to a new file and still keep all the linked instances?

Yes, it is possible with Master plugin. Check out the instructions in this post: Move master components from different files to a new library - #2 by Gleb. You will need to do this for both components individually (copy A, pick A, link A; copy B, pick B, link B).