Transformation between aspect ratio

I am trying to measure width of an object in image. The object size is 2D object 15cm X 15cm.

When I capture a frame with resolution 1280 X 720 (16:9) I am getting that the object width is 50px.

But when I capture a frame resolution 640 X 480 (4:3) I am getting that the object width is 30px.

The distance between the object and the camera did not changed during the test. I didn't find a transformation that can convert the width in pixels from 1280 X 720 to 640 X 480. I think that the aspect ratio is the issue here but I didn't succeed to solve it out.

How can I know that the width in pixels is both resolutions is actually the same object size?

$$\frac{50\text{ px}}{720\text{ px}} \approx \frac{30\text{ px}}{480\text{ px}}$$