Fix canny segment fault (Bug #3978)

Avoid too large size cause std::vector::resize() failed.
Please refer to http://code.opencv.org/issues/3978.

check_regression=*anny*

Sure. I will.