How to pass cv::ptr to lambda


Below you can see simple code snippet where I just try to pass cv::ptr to lambda. But it gives an error like :

  what():  OpenCV(4.4.0) /home/opencv_contrib/modules/cudaobjdetect/src/cas             cadeclassifier.cpp:155: error: (-217:Gpu API call) NCV Assertion Failed: NCVMemStackAllocator dtor:: not all objects were deallocated properly, forcing destruction, 
file=/home/opencv_contrib/modules/cudalegacy/src/NCV.cpp, line=397 in              function 'NCVDebugOutputHandler'

Aborted (core dumped)

The code part:

    cv::Ptr<cv::cuda::CascadeClassifier> cascade = cv::cuda::CascadeClassifier::create("haarcascade_frontalface_default.xml");

        Mat frame;

        if ( ! ) {
            cerr << "Can not read frame from webcam";
            return -1;

std::thread([frame, cascade](){
                std::vector<cv::Rect> h_found;
                cv::cuda::GpuMat d_frame, d_gray, d_found;
                cv::cuda::cvtColor(d_frame, d_gray, cv::COLOR_BGR2GRAY);
                cascade->detectMultiScale(d_gray, d_found);
                cascade->convert(d_found, h_found);

                for(int i = 0; i < h_found.size(); ++i)
                        rectangle(frame, h_found[i], Scalar(0,255,255), 5);


My question is how can I pass cv::ptr to lambda ? I want to pass this to many lambdas if it is needed.
I just want to copy and pass the cascade but it gives core dump.

Thank you.