Passing variables to where clause

in the documentation here , I could find an example of passing variable to a query. That portion refers to model.

 public function findFavorites(Query $query, array $options)
    {
        $for = $options['for'];
        return $query->matching('Users.Favorites', function ($q) use ($for) {
            return $q->where(['Favorites.user_id' => $for]);
        });
    }

Passing variables is handy in controllers who receives Request and then make a query that uses variables coming from the Request. It seems like contain, matching ( and perhaps andWhere and orWhere) can make use of this function ($q) use ($myVariable)… form, but that where cannot use it.
I do need to write a where clause using $startDate and $endDate variables …
I am new to Cakephp, this actually my first post on the forum. Thanks for any help