To cancel a match that you've invited a player to, but that hasn't been accepted yet, go to the match page and press cancel. The match will be canceled immediately.
If you want to cancel a match that's already been accepted, again, press the Cancel Match button on the match page. Your opponent will have to approve your cancellation request.
If you decide you don't want to cancel, make sure to undo your cancellation request! Otherwise, if you play the match and win, your opponent will be able to accept your cancellation request and the match won't count. There's nothing we can do for you in this situation!