Robust distortion correction of endoscope