First version of distance min between two images (recursive version)