The smaller the field of view (FOV) and the shorter the working distance of a lens, the smaller the achievable depth of field (DOF).
In a FOV of 5x5mm the DOF, might only be 1/10mm.
However, if we want to measure the relative position of two objects with a height difference of 5mm, for example, it is clear that only one of the objects can be imaged sharply.
But there is a trick you can use, which makes it possible to focus on two different working distances at the same time, even if the distance between them is quite large. The idea comes from the observation that plane-parallel glass (such as a filter, a window) changes the distance in the optical path that is necessary for focusing. As additional glass causes aberrations (chromatic aberration, coma), this trick works best, or “only” with telecentric lenses.
If you focus on an object at a 60mm distance for example, and add a 1cm thick optical glass between the object and the lens, it is observed that the camera must be moved about 3mm backwards for the object to appear sharp again.
If you leave the camera in its original position, the focal plane moves instead. The trick is to cover only half the picture with a glass plate – another reason why the lens must be telecentric.