If the system is in a state of static equilibrium (meaning no motion) then according to Newton's Second Law, the net force and the net torque acting on the system must both add up to zero. In order for the forces to cancel, the downward force of gravity must be balanced by the upward force of the glass acting on the matchstick. So far, so good. But for the torques to cancel, the center of gravity of the object must lie directly over the rim of the glass. The center of gravity of an object is the point at which the gravity force seems to act. It's like the statistical average of all the gravitational forces acting on each small piece of the object.