cudaMalloc() and cudaMemcpy() doesn't work as expected

I have a strange issue of flickering display(green flutter coming in between) when I try to allocate memory on GPU and copying a frame(1080p) captured by OpenCV VideoCapture(). I have a Pascal GPGPU with cuda 9.0 CUDA installed.

/* Header files */
#include <cuda.h>
#include <cuda_runtime.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <linux/videodev2.h>
#include <iostream>

/*Definitions */
#define DEFAULT_FRAME_Y 1080 
#define DEFAULT_FRAME_X 1920 

cv::Mat frameIn(DEFAULT_FRAME_Y, DEFAULT_FRAME_X, CV_8UC3); //Input Frame
cv::Mat frameYCbCr(DEFAULT_FRAME_Y, DEFAULT_FRAME_X,CV_8UC3); // YCbCr Frame
cv::Mat frameYUV(DEFAULT_FRAME_Y, DEFAULT_FRAME_X, CV_8UC2); //YUV 4:2:2
int main()
{ 
    VideoCapture camera(0);
    if(!camera.isOpened())
        return -1;
    while(1)
    {
        camera >> frameIn;
        unsigned char *d_in;

        /* Flickering starts if I enable cudaMalloc() */
    //  cudaMalloc(&d_in, numRows*numCols*sizeof(char));
        cudaMemset(&d_in, 0, numRows*numCols);
        cudaMemcpy(d_in, frameIn.data, numRows*numCols*sizeof(char), cudaMemcpyHostToDevice);
        cvtColor(frameIn, frameYCbCr, CV_BGR2YUV);

        /* This function converts YUV(4:4:4) to YUV(4:2:2) */
        ConvertYUV444ToYUV422(frameYCbCr.data, 1920, 1080, frameYUV.data); 
        memcpy(bufsOut, frameYUV.data, numRows*numCols*2);
        cudaFree(d_in);

        /*The bufsOut is then viewed on a display over V4L2 which flickers */
    }
}