How to connect 2 Arduino together?

You don't have to use motor shields. There are other motor drivers that do not cover up all the Arduino pins so that you would not be limited to 2 motors.

I presume the shield you have is sized to fit an Uno so that many of the Mega pins are uncovered?

If so I suggest you look at (for example) the motor drivers that are on the Pololu website - many of them could be connected into some of the vacant Mega pins. Other suppliers have similar products.

If you really want to connect your two Megas together then the simplest way is to connect them using Serial1 on each board. Connect Rx1 to Tx1 on the other board and Tx1 to Rx1. Also make a GND connection between the boards. For receiving data have a look at the examples in Serial Input Basics - simple reliable ways to receive data. It will need a minor change to work with Serial1.

...R