DIS optical flow SIGSEGV error when changing parameters

Hi, I try to use a dataset to calculate optical flow results with OpenCV.
But when I try different parameters, the code seems very unstable, often showing this error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

My OpenCV version : 3.4.5 (DIS is in opencv contrib)
Good parameters: PRESET_ULTRAFAST,PatchSize(25), PatchStride(5), FinestScale(2).
when I set the FinestScale to 1 or 0 or change patch size, it often doesn’t work for the whole dataset(sometimes only 2 frames, sometimes more than 20 frames ) and get the error.
I want to get as good as possible results within a time limit so I need to tune the parameters.

dataset: Computer Vision Group - Dataset Download

the code for reproducing

#include <opencv2/optflow.hpp>
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <fstream>
#include <chrono>

using namespace cv;
using namespace std;
void LoadImagesTUM(const string &strAssociationFilename, vector<string> &vstrImageFilenamesRGB)
{
    ifstream fAssociation;
    fAssociation.open(strAssociationFilename.c_str());
    while(!fAssociation.eof())
    {
        string s;
        getline(fAssociation,s);
        if(!s.empty())
        {
            stringstream ss;
            ss << s;
            double t;
            string sRGB, sD;
            ss >> t;
            ss >> sRGB;
            vstrImageFilenamesRGB.push_back(sRGB);
            ss >> t;
            ss >> sD;

        }
    }
}

int main(int argc, char **argv)
{
    vector<string> rgbimgs;
    LoadImagesTUM("/path/tum_freiburg3_walking_xyz/association.txt", rgbimgs);
    int nImages = rgbimgs.size();
    cout << "nImages size " << nImages << endl;
    cv::Mat imRGB, imGPast, imGCur;
    cv::Mat flow_uv[2];
    cv::Mat hsv_split[3], hsv;
    char ret;
    cv::Mat mag, ang, rgb;
    for(int i=0; i< nImages; i++){
        imRGB = cv::imread(string("/home/wenyan/Documents/tum_dataset/forNN/tum_freiburg3_walking_xyz/"+rgbimgs[i]),CV_LOAD_IMAGE_UNCHANGED);
        if(i==0){
            cv::cvtColor(imRGB, imGPast, COLOR_BGR2GRAY);
            continue;
        }
        // calculate optical flow
        cv::cvtColor(imRGB, imGCur, COLOR_BGR2GRAY);
        cv::Mat flow(imGCur.size(), CV_32FC2);
        std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
        auto dis = cv::optflow::createOptFlow_DIS(cv::optflow::DISOpticalFlow::PRESET_ULTRAFAST);
        dis->setPatchSize(25);
        dis->setPatchStride(5);
        dis->setFinestScale(2);
        dis->calc(imGPast, imGCur, flow);
        std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
        double ttrack= std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
        cout << "time / frame :" << ttrack << endl;
        split(flow, flow_uv);
        multiply(flow_uv[1], -1, flow_uv[1]);
        cartToPolar(flow_uv[0], flow_uv[1], mag, ang, true);
        normalize(mag, mag, 0, 1, NORM_MINMAX);
        hsv_split[0] = ang;
        hsv_split[1] = mag;
        hsv_split[2] = Mat::ones(ang.size(), ang.type());
        merge(hsv_split, 3, hsv);
        cvtColor(hsv, rgb, COLOR_HSV2BGR);
        imshow("flow", rgb);
        imshow("orig", imRGB);
        std::swap(imGPast, imGCur);

    }

}

Could anyone tell me how to solve this or the possible reason? Really thanks for your help!!

btw. my Operating System / Platform : ubuntu 18.04 64bit