Increasingly optimistic venture capitalists invested $6.35 billion in startups during the second quarter, marking the biggest burst of dealmaking in more than four years.