fix crash when sample point out of image boundaries
Merge pull request #3485 from mapycz:fix-calibrate-crash