importing upstream diff http://code.opencv.org/projects/opencv/repository/revisions/e9b9a6fc038fc243e2debcc1dabd0d0745ff39d6/diff/modules/legacy/src/dpstereo.cpp