Ignore identical collisions

My game scene ground is made of multiple individual objects (bricks). I want to detect collision with the ground but at the same time ignore the collision instances when the character transitions from a brick to another. At the moment, any code that I write in the onContactEnd collision with the bricks, it gets executed every time the player transitions from a brick to another, despite the bricks being connected with eachother.

So I have the code:

bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
        if ((1 == a->getCollisionBitmask() && 4 == b->getCollisionBitmask()) || (4 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))
	{
		brickcontact = 1;
		return true;
	}
}


bool GameScene::onContactEnd(cocos2d::PhysicsContact &contact)
{
	PhysicsBody *a = contact.getShapeA()->getBody();
	PhysicsBody *b = contact.getShapeB()->getBody();
        if ((1 == a->getCollisionBitmask() && 4 == b->getCollisionBitmask()) || (4 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))
	{
		brickcontact = 0;
		return true;
	}
}

I update the player in an update function depending on the brickcontact value. I want to tell the listener to wait before calling a method if the brickcontact hasn’t been modified in the last 0.2-0.5 seconds or so AND if it’s 0 (basically when I leave the ground AND not being in contact with it for an amount of time).

I feel like this is easy to implement, but I don’t know what to use.

Can you show some more code in setting your bitmasks? Also I can quite visualize this. Have a screenshot of your game?

So this is the code used to create the brick objects that are used to create the ground:

	brickbox = Sprite::create("brick1.png");
	this->setAnchorPoint(Point(0, 0));
	this->setPosition(Point(brickbox->getBoundingBox().size.width * x, brickbox->getBoundingBox().size.height * y));
	brickbody = PhysicsBody::createBox(Size(32,32), PhysicsMaterial(0, 0, 0));
	brickbody->setCollisionBitmask(4);
	brickbody->setContactTestBitmask(true);
	brickbody->setDynamic(false);
	this->setPhysicsBody(brickbody);

I pass x and y as int values for positions. The game scene looks like this: https://i.imgur.com/y2l9dXL.png
Basically, a brick ends where another one starts (so if one occupies 0-32 on X axis, the next one occupies 32-64 and so on). It gives an impression of continuity.

I also set the player bitmask every time I execute an action (changing direction of movement).

    playerbody->setCollisionBitmask(1);
	playerbody->setContactTestBitmask(true);

Should I apply collisionbitmask every time I change movement direction or is that wrong practice? I also have this code that’s in my update schedule:

                playerbody->setMoment(INFINITY);
		playerbody->setGravityEnable(true);
		playerbody->setVelocity(Vec2(70,0));
		playerbody->setCollisionBitmask(1);
		playerbody->setContactTestBitmask(true);
		this->setPhysicsBody(playerbody);

Removing the collisionbitmask settings in this case doesn’t appear to fix it.