some formal changes

1. Adding constness
2. Replacing cv::Mat low-level pointer operations with method call, for example:
        dst.data + i*dst.step -> dst.ptr(i)
        (float*)w.data -> w.ptr<float>()