Mark Gatiss has confirmed on Twitter that the ending, where a lonely Sherlock leaves John's wedding, is a deliberate homage to the final scene of this story, in which the Doctor quietly leaves Jo's wedding
When Sholto is getting dressed in his military uniform before the wedding it is shot and edited in the exact same manner as the opening of Mishima when he puts on his military uniform.
The unexplained glowing on Sherlocks face when he opens the matchbox, spoofs the scene where John Travolta opens the briefcase in Brett's apartment. We never find out what is in either of them.