When the matches burn inside the glass, the air inside the glass warms. Warm air takes up more space than cool air. As the air inside the glass gets warmer, it expands and pushes against the sides, creating higher air pressure inside the glass than outside the glass. To restore the balance, some of the high pressure air inside tries to move towards the lower pressure air outside.
The matches burns in a combustion reaction. For the matches to stay a light, it needs a constant supply of oxygen. However, when the matches is trapped in the glass, it quickly uses the available oxygen. When there isn’t enough oxygen inside the glass, the matches stops burning.