Real time video delay + distort

I’ve been trying to delay a video and some add distortion to it. I referred to a previous post by roy mcdonalds and distortion example in ofxCv but there is some problem which I’m not able to comprehend.
ofApp.cpp

#include "ofApp.h"

using namespace ofxCv;
using namespace cv;

void ofApp::setup(){
    camWidth = 2550;  // try to grab at this size.
    camHeight = 1600;
    vidGrabber.setDeviceID(0);
    vidGrabber.setDesiredFrameRate(60);
    vidGrabber.initGrabber(camWidth, camHeight);
    ofSetVerticalSync(true);
    
    nDelayFrames = 500; //Set buffer size
    buffer.setup(nDelayFrames);
	 mesh.setMode(OF_PRIMITIVE_TRIANGLES);
    	 stepSize = 8;
   	 ySteps = vidGrabber.getHeight() / stepSize;
   	 xSteps = vidGrabber.getWidth() / stepSize;
   	 for(int y = 0; y < ySteps; y++) {
        	for(int x = 0; x < xSteps; x++) {
            	mesh.addVertex(ofVec3f(x * stepSize, y * stepSize, 0.0));
           	mesh.addTexCoord(ofVec2f(x * stepSize, y * stepSize));
        	}
    	}
    		for(int y = 0; y + 1 < ySteps; y++) {
       			 for(int x = 0; x + 1 < xSteps; x++) {
           		 int nw = y * xSteps + x;
            		 int ne = nw + 1;
            		 int sw = nw + xSteps;
           		 int se = sw + 1;
           		 mesh.addIndex(nw);
           		 mesh.addIndex(ne);
          		 mesh.addIndex(se);
            		 mesh.addIndex(nw);
            		 mesh.addIndex(se);
            		 mesh.addIndex(sw);
        		 }
    		} 
}

//--------------------------------------------------------------
void ofApp::update(){

    vidGrabber.update();
    
    if(vidGrabber.isFrameNew()){
        buffer.pushPixels(vidGrabber.getPixels());
	flow.setWindowSize(8);
        flow.calcOpticalFlow(vidGrabber);
        int i = 0;
        float distortionStrength = 4;
        for(int y = 1; y + 1 < ySteps; y++) {
            for(int x = 1; x + 1 < xSteps; x++) {
                int i = y * xSteps + x;
                ofVec3f position(x * stepSize, y * stepSize, 0.0);
                ofRectangle area(position - ofVec3f(stepSize, stepSize, 0.0) / 2, stepSize, stepSize);
                ofVec2f offset = flow.getAverageFlowInRegion(area);
                mesh.setVertex(i, position + distortionStrength * offset);
                i++;
            }
        }
    }
    
}


//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(255);
    
    //vidGrabber.draw(20, 20);

    int ind = ofMap(500, 0, ofGetWidth(), 0, nDelayFrames-1, true);

    
//    ofDrawBitmapStringHighlight(ofToString(ind), 20, camHeight+40);
    
    ofTexture tex;
    tex.loadData(buffer.getDelayedPixels(ind));
		tex.bind();
		mesh.draw();
		tex.unbind();
   // tex.draw(2, 2);
    
}

ofApp.h


class circularPixelBuffer{
public:
    circularPixelBuffer(){
        currentIndex = 0;
    }
    void setup(int numFrames){
        frames.resize(numFrames);
        currentIndex = numFrames -1;
    }
    void pushPixels(ofPixels& pix){
        currentIndex--;
        if (currentIndex < 0) {
            currentIndex = frames.size() -1;
        }
        frames[currentIndex] = pix;
    }
    
    ofPixels& getDelayedPixels(size_t delay){
        if(delay < frames.size()){
            return frames[ofWrap(delay + currentIndex, 0, frames.size())];
        }
        return frames[0];
    }
    
protected:
    int currentIndex;
    vector<ofPixels> frames;
};

class ofApp : public ofBaseApp {
public:
    void setup();
    void update();
    void draw();

    ofVideoGrabber vidGrabber;
    int camWidth;
    int camHeight;

	ofxCv::FlowFarneback flow;
	ofMesh mesh;
	int stepSize, xSteps, ySteps;
    
    int nDelayFrames;
    
    circularPixelBuffer buffer;

};

The delay and distort code are individually working. but how do i apply the mesh on the feed uploaded from the buffer?