Please note that the frame "car" is not a inertial frame, then on both masses M1 and M2, is acting the fictitious force whose magnitude is equal to M1 A for the body 1, and whose magnitude is M2 A for the body 2, where A is the magnitude acceleration of the system, body 1+ body 2. the situation is represented in the picture file attached below. Please note that I called with g the gravity, and with T the magnitude of the tension exerted by the rope on the bodies 1 and 2.
The equation of motion of the body 1 is:
-M1 A +T = M1 a (1)
here a is the magnitude of the acceleration of the body 1, which in turn is also the magnitude of the acceleration of the body 2
The equation of motion of the body 2, is:
-m2 g + T = - M2 a (2)
Furthermore, I called with R the reaction exerted by the car on the body M2.
Solving the system constituted by the equations 1 and 2, we get the subsequent value for the magnitude of the acceleration A: