Dundalk missed out on a place in the Champions League group stage after suffering a 3-1 aggregate defeat to Legia Warsaw.